<style lang="scss">
	/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
	@import "uview-ui/index.scss";
</style>

<script>
	export default {
		globalData:{
			//全局变量储存用户的Authority和openid
			Authority: '',
			openid: '',
			searchList: [],
			screenHeightRpx: '',
			header: '',
			user: ''
		},
		onLaunch: function() {
			
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods:{
			watch: function(key, method) {
				var obj = this.globalData;
				//加个前缀生成隐藏变量，防止死循环发生
				getApp().globalData[key + 'tmp'] = obj[key]; //obj[key]这个不能放在Object.defineProperty里
				if (getApp().globalData[key + 'tmp']) { //处理已经声明的变量，绑定处理
					method(getApp().globalData[key + 'tmp']);
				}
				Object.defineProperty(obj, key, {
					configurable: true,
					enumerable: true,
					set: function(value) {
						getApp().globalData[key + 'tmp'] = value;
						method(value);
					},
					get: function() {
						return getApp().globalData[key + 'tmp']
					}
				})
			},
			//通用接口函数
			async UniRequest(path, method, body, header) {
				let data
				let request = new Object
				// request.url = "http://119.91.78.179:9001"+path
				// request.url = "https://www.zcjn.top/"+path
				
				//request.url = "https://course-1383871-1308162715.ap-shanghai.run.tcloudbase.com"+path
				// request.url = "http://127.0.0.1:9005"+path
				request.url = "http://120.79.194.74:9005"+path
				// request.url = "http://39.108.231.10:9100"+path
				request.method = method
				if (body){
					request.data = body
				}
				if (header){
					request.header = header
				}
				await uni.request(request).then(res=>{data = res})
				return data[1].data
			}
		} 
	}
</script>
